﻿Public Class MyDynamicValidator
    Inherits DynamicValidator
    Protected Overrides Sub ValidateException(exception As Exception)
        ' If it's not already an exception that DynamicValidator looks at   
        If Not (TypeOf exception Is IDynamicValidatorException) AndAlso Not (TypeOf exception Is ValidationException) Then
            ' Find the most inner exception
            While exception.InnerException IsNot Nothing
                exception = exception.InnerException
            End While
            ' Wrap it in a ValidationException so the base code doesn't ignore it
            If ExceptionShouldBeDisplayedInPage(exception) Then
                exception = New ValidationException(Nothing, exception)
            End If
        End If
        ' Call the base on the (possibly) modified exception
        MyBase.ValidateException(exception)
    End Sub
    Private Function ExceptionShouldBeDisplayedInPage(e As Exception) As Boolean
        ' This is where you may want to add logic that looks at the exception and
        ' decides whether it should indeed be shown in the page
        Return True
    End Function
End Class